<template>
    <div style="width: 66%;display: flex">
      <div style="flex:5"></div>
      <div style="flex:5">
      <el-form label-position="top" label-width="80px" :model="formData" class="login-form">
        <h2>用户登录</h2>
        <el-form-item label="用户名">
          <el-input v-model="formData.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="formData.password" type="password"></el-input>
        </el-form-item>
        <el-button @click="login"  type="primary">登录</el-button>
      </el-form>
    </div>
    </div>
</template>

<script>
export default {


  data() {
    return {
      formData: {
        username: '',
        password: ''
      }
    }
  },
  mounted()
  {
    this.load()

  },
  methods:
      {
       async login()
        { console.log(this.formData)
          let result= await this.$axios.post('/log',this.formData);
          console.log(result)
          let axiosResponse = await this.$axios.get('/logONE/'+this.formData.username);
           console.log(axiosResponse.data);
          if(result.status==200)
          {
           localStorage.setItem('bike',axiosResponse.data.img)
            localStorage.setItem('bikeId',axiosResponse.data.id)
            this.$router.push('/')
            console.log(111)
          }
          else
          {
            this.$message(
                {
                  type:'error',
                  message:'用户名或密码错误'
                }

            )
          console.log(this.formData)
            console.log(222)
          }


        },
        async load()
        {
          console.log("111")
        }

      }

}
</script>

<style scoped>

</style>